package com.study.seckill.web.page;

import com.study.seckill.entity.CourseSeckill;
import com.study.seckill.service.CourseSeckillService;
import com.study.seckill.vo.CourseSeckillDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName: CourseSeckillController
 * @Author: wYin
 * @Date: 2022/3/10 14:48
 */
@Controller
@RequestMapping("/page/courseSeckill")
public class CourseSeckillController {
    @Autowired
    private CourseSeckillService courseSeckillService;

    /**
     * @Desc: 秒杀课程展示--可展示的课程列表
     * @Param: [model]
     * @Return: java.lang.String
     * @Author: wYin
     * @Time: 2022/3/10 15:10
     */
    @GetMapping("/showList")
    public String showList(Model model){
        List<CourseSeckill> courseSeckills = courseSeckillService.showCourseSeckill();
        model.addAttribute("data",courseSeckills);
        return "seckill_list";
    }

    @GetMapping("/add")
    public String add(){
        return "seckill_add";
    }

    @PostMapping("/add")
    public String add(CourseSeckill courseSeckill,Model model){
        //执行秒杀课程添加
//        String addResult = courseSeckillService.add(courseSeckill);
        //todo 判断并反馈信息
        model.addAttribute("msg","成功");
        return "seckill_add";
    }

    @GetMapping("/courseList")
    public String courseList(){
        return "seckill_course_select";
    }
    
    @GetMapping("/item/{id}")
    public String item(@PathVariable("id")Integer id, Model model){
        //根据秒杀id查询
        CourseSeckillDetailVO result = courseSeckillService.getSeckillInfoById(id);
        model.addAttribute("data",result);
        return "item";
    }

}
